<?php

namespace app\admin\model\sport;

use think\Model;
use app\admin\model\sport\Area;
use app\admin\model\sport\ScoreType;


class Score extends Model
{

    

    

    // 表名
    protected $name = 'sport_score';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'score_type_text',
        'sex_text',
        'unit_text',
        'status_text'
    ];
    

    
    public function getScoreTypeList()
    {
        return ['middle' => __('Score_type middle'), 'senior' => __('Score_type senior')];
    }

    public function getSexList()
    {
        return ['1' => __('Sex 1'), '2' => __('Sex 2')];
    }

    public function getUnitList()
    {
        return ['ms' => __('Unit ms'), 'meter' => __('Unit meter'), 'cmeter' => __('Unit cmeter'), 'sec' => __('Unit sec'), 'an' => __('Unit an')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Status normal'), 'hidden' => __('Status hidden')];
    }


    public function getScoreTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['score_type']) ? $data['score_type'] : '');
        $list = $this->getScoreTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getUnitTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['unit']) ? $data['unit'] : '');
        $list = $this->getUnitList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function area()
    {
        return $this->belongsTo(Area::class, 'sport_area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function stype()
    {
        return $this->belongsTo(ScoreType::class, 'sport_type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
